package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.HsHouse;
import com.ruoyi.business.service.IHsHouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房屋Controller
 * 
 * @author asher
 * @date 2021-11-08
 */
@RestController
@RequestMapping("/business/house")
public class HsHouseController extends BaseController
{
    @Autowired
    private IHsHouseService hsHouseService;

    /**
     * 查询房屋列表
     */
    @PreAuthorize("@ss.hasPermi('business:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsHouse hsHouse)
    {
        startPage();
        List<HsHouse> list = hsHouseService.selectHsHouseList(hsHouse);
        return getDataTable(list);
    }

    /**
     * 导出房屋列表
     */
    @PreAuthorize("@ss.hasPermi('business:house:export')")
    @Log(title = "房屋", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsHouse hsHouse)
    {
        List<HsHouse> list = hsHouseService.selectHsHouseList(hsHouse);
        ExcelUtil<HsHouse> util = new ExcelUtil<HsHouse>(HsHouse.class);
        return util.exportExcel(list, "房屋数据");
    }

    /**
     * 获取房屋详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:house:query')")
    @GetMapping(value = "/{houseId}")
    public AjaxResult getInfo(@PathVariable("houseId") Long houseId)
    {
        return AjaxResult.success(hsHouseService.selectHsHouseByHouseId(houseId));
    }

    /**
     * 新增房屋
     */
    @PreAuthorize("@ss.hasPermi('business:house:add')")
    @Log(title = "房屋", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsHouse hsHouse)
    {
        return toAjax(hsHouseService.insertHsHouse(hsHouse));
    }

    /**
     * 修改房屋
     */
    @PreAuthorize("@ss.hasPermi('business:house:edit')")
    @Log(title = "房屋", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsHouse hsHouse)
    {
        return toAjax(hsHouseService.updateHsHouse(hsHouse));
    }

    /**
     * 删除房屋
     */
    @PreAuthorize("@ss.hasPermi('business:house:remove')")
    @Log(title = "房屋", businessType = BusinessType.DELETE)
	@DeleteMapping("/{houseIds}")
    public AjaxResult remove(@PathVariable Long[] houseIds)
    {
        return toAjax(hsHouseService.deleteHsHouseByHouseIds(houseIds));
    }
}
